import axios from 'axios'

const service = axios.create({
    baseURL: import.meta.env.VITE_API_BASE || '/api',
    timeout: 5000
})

service.interceptors.response.use(
    response => {
        if (response.data.code !== 0) {
            return Promise.reject(new Error(response.data.message || 'Error'))
        }
        return response.data.data
    },
    error => {
        return Promise.reject(error)
    }
)

export default service